package com.playball.lottery.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import android.util.Log;

/**
 * 合买大厅相关工具类
 * 
 * @author Administrator
 * 
 */
public class HemaiDateUtil {

	/**
	 * 
	 * @param marketCode
	 *            彩种，中文代码字符串
	 * @return 数字代号
	 */
	public static String stringToNumber(String marketCode) {
		if (marketCode.equals("全部")) {
			return "0";
		} else if (marketCode.equals("竞彩足球")) {
			return "90";
		} else if (marketCode.equals("竞彩篮球")) {
			return "91";
		} else if (marketCode.equals("北单")) {
			return "45";
		} else if (marketCode.equals("胜负彩")) {
			return "1";
		} else if (marketCode.equals("任选九")) {
			return "19";
		} else if (marketCode.equals("双色球")) {
			return "5";
		} else if (marketCode.equals("超级大乐透")) {
			return "39";
		} else if (marketCode.equals("其他数字彩")) {
			return "-1";
		} else {
			return "0";
		}
	}

	/**
	 * String 78%,+25% 去掉+和%
	 * 
	 * @return int 78,25 etc
	 */

	public static int StringToint(String str) {
		int intProcess = 0;
		if (str.contains("+")) {

			if ("".equals(str.split("%")[0])) {
				intProcess = 0;
			} else {
				String strProcess2;
				String strProcess2Sub;
				strProcess2 = str.split("%")[0];
				int intIndex = strProcess2.indexOf("+");

				strProcess2Sub = strProcess2.substring(intIndex + 1);

				intProcess = Integer.parseInt(strProcess2Sub);
			}

		} else {

			if ("".equals(str.split("%")[0])) {
				intProcess = 0;
			} else {
				intProcess = Integer.parseInt(str.split("%")[0]);
			}

		}

		return intProcess;
	}

	/**
	 * String 78%,+25% 去掉+和%
	 * 
	 * @return String 78,25 etc
	 */

	public static String StringTointStr(String str) {
		String strProcess;
		if (str.contains("+")) {

			if ("".equals(str.split("%")[0])) {
				strProcess = "0";
			} else {
				String strProcess2;

				strProcess2 = str.split("%")[0];
				int intIndex = strProcess2.indexOf("+");

				strProcess = strProcess2.substring(intIndex + 1);

			}

		} else {

			if ("".equals(str.split("%")[0])) {
				strProcess = "0";
			} else {
				strProcess = str.split("%")[0];
			}

		}

		return strProcess;
	}

	/**
	 * 对list进行排序
	 * 
	 * @param list
	 *            数据
	 * @param intOrderType
	 *            升序，降序
	 * @param intOrderField
	 *            进度，战绩，总额
	 * @return排序后list
	 */
	public static List<Map<String, Object>> SortListData(List<Map<String, Object>> list, final int intOrderType, final int intOrderField) {

		if (!list.isEmpty()) {
			Collections.sort(list, new Comparator<Map<String, Object>>() {
				@Override
				public int compare(Map<String, Object> object1, Map<String, Object> object2) {
					int result = 0;
					int intO1P1 = Integer.parseInt(String.valueOf(object1.get("Schedule")));
					int intO1P2 = Integer.parseInt(String.valueOf(object1.get("Assure")));
					int intO2P1 = Integer.parseInt(String.valueOf(object2.get("Schedule")));
					int intO2P2 = Integer.parseInt(String.valueOf(object2.get("Assure")));
					// 降序
					if (intOrderType == 0) {

						if (intOrderField == 3) {
							if ((intO2P1 + intO2P2) > (intO1P1 + intO1P2)) {
								result = 1;
							} else if ((intO2P1 + intO2P2) == (intO1P1 + intO1P2)) {
								result = 0;
							} else {
								result = -1;
							}

						} else if (intOrderField == 5) {
							if (Integer.parseInt(String.valueOf(object2.get("Level"))) > Integer.parseInt(String.valueOf(object1.get("Level")))) {
								result = 1;
							} else if (Integer.parseInt(String.valueOf(object2.get("Level"))) == Integer.parseInt(String.valueOf(object1.get("Level")))) {
								result = 0;
							} else {
								result = -1;
							}
						} else if (intOrderField == 1) {
							if (Integer.parseInt(String.valueOf(object2.get("Share"))) > Integer.parseInt(String.valueOf(object1.get("Share")))) {
								result = 1;
							} else if (Integer.parseInt(String.valueOf(object2.get("Share"))) == Integer.parseInt(String.valueOf(object1.get("Share")))) {
								result = 0;
							} else {
								result = -1;
							}
						}

					} else if (intOrderType == 1) {// 升序
						if (intOrderField == 3) {
							if ((intO1P1 + intO1P2) > (intO2P1 + intO2P2)) {
								result = 1;
							} else if ((intO1P1 + intO1P2) == (intO2P1 + intO2P2)) {
								result = 0;
							} else {
								result = -1;
							}

						} else if (intOrderField == 5) {
							if (Integer.parseInt(String.valueOf(object1.get("Level"))) > Integer.parseInt(String.valueOf(object2.get("Level")))) {
								result = 1;
							} else if (Integer.parseInt(String.valueOf(object1.get("Level"))) == Integer.parseInt(String.valueOf(object2.get("Level")))) {
								result = 0;
							} else {
								result = -1;
							}
						} else if (intOrderField == 1) {
							if (Integer.parseInt(String.valueOf(object1.get("Share"))) > Integer.parseInt(String.valueOf(object2.get("Share")))) {
								result = 1;
							} else if (Integer.parseInt(String.valueOf(object1.get("Share"))) == Integer.parseInt(String.valueOf(object2.get("Share")))) {
								result = 0;
							} else {
								result = -1;
							}
						}

					}

					return result;
				}
			});

		}
//		Log.e("list after sort= ", list.toString());
		return list;
	}

}
